﻿using AutoMapper;
using MediatR;
using MyMES.Domain.zyy;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.Requisitions;

namespace MyMES.Writer.API.Application.CommendHandlers.Requisitions
{
    public class RequisitionHandler : IRequestHandler<RequisitionCommand, APIResult<Requisition>>
    {
        private readonly IBaseRepository<Requisition> baseRepository;
        private readonly IMapper mapper;

        public RequisitionHandler(IBaseRepository<Requisition> baseRepository, IMapper mapper)
        {
            this.baseRepository = baseRepository;
            this.mapper = mapper;
        }
        public async Task<APIResult<Requisition>> Handle(RequisitionCommand request, CancellationToken cancellationToken)
        {

            APIResult<Requisition> result = new APIResult<Requisition>();
            result.Code = APIEnum.添加成功;
            result.Msg = "添加成功";
            var model = mapper.Map<Requisition>(request);
            string str = "insert Requisition (RequisitionNum,RequisitionName,RequisitionOrder,Workstation,CustomerId,Customer_name,CustomerTime,Documentstatus) values(@RequisitionNum,@RequisitionName,@RequisitionOrder,@Workstation,@CustomerId,@Customer_name,@CustomerTime,@Documentstatus)";
            await baseRepository.Insert(model, str);
            return result;
        }
    }
}
